var Ball = function(game){
    var o = game.imgByName("ball")
    o.x = 150
    o.y = 230
    o.speedX = 10
    o.speedY = -10
    o.fired = false
    o.fire = function(){
        o.fired = true
    }
    o.reboundFrom = function(it){
        var hasCollide = false

        o.speedY = -o.speedY
        o.x += o.speedX
        o.y += o.speedY
        hasCollide = collide(o, it)
        o.x -= o.speedX
        o.y -= o.speedY
        if (hasCollide){
            o.speedY = -o.speedY
            o.speedX = -o.speedX
        }
    }
    o.move = function(){
        if (o.fired){
            if (o.x < 0 || o.x + o.img.width > 400){
                o.speedX = -o.speedX
            }
            if (o.y < 0 || o.y + o.img.height > 300){
                o.speedY = -o.speedY
            }
            o.x += o.speedX
            o.y += o.speedY
        }
    }
    o.clickd = function(mouseX, mouseY){
        if (o.x <= mouseX && mouseX <= o.x + o.img.width 
             && o.y <= mouseY && mouseY <= o.y + o.img.height){
            return true
        }
        return false
    }

    return o
}